// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'whatwg-fetch';
import 'custom-event-polyfill';
import 'core-js/stable/promise';
import 'core-js/stable/symbol';
import 'core-js/stable/string/starts-with';
import 'core-js/web/url';
import Vue from 'vue';
import App from './App';
import './common/js/actions';
import report from './plugins/report';
import { router } from './router';
import store from './store/store';
import i18n from './lang';
import './common/css/element-variables.scss';
import ElementUI from '@ayitubie/element-ui';
import './font/iconfont.css';
import './common/css/reset.css';
import filters from './filters'; //自定义过滤器，挂在到Vue全局
import autoFocus from '@/directives/autoFocus';
import waterMaker from '@/directives/waterMaker';

import VueCropper from 'vue-cropper';
import * as MITO from '@zyf2e/monitor-web';

// import VMdPreview from '@kangc/v-md-editor/lib/preview';
// import '@kangc/v-md-editor/lib/style/preview.css';
// import githubTheme from '@kangc/v-md-editor/lib/theme/github.js';
// import '@kangc/v-md-editor/lib/theme/style/github.css';

// // highlightjs
// import hljs from 'highlight.js';

// VMdPreview.use(githubTheme, {
//   Hljs: hljs,
// });

// Vue.use(VMdPreview);
import VMdPreview from '@kangc/v-md-editor/lib/preview';
import '@kangc/v-md-editor/lib/style/preview.css';
import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js';
import '@kangc/v-md-editor/lib/theme/style/vuepress.css';
import createMermaidPlugin from '@kangc/v-md-editor/lib/plugins/mermaid/cdn';
import createLineNumbertPlugin from '@kangc/v-md-editor/lib/plugins/line-number/index';
import createCopyCodePlugin from '@kangc/v-md-editor/lib/plugins/copy-code/index';
import '@kangc/v-md-editor/lib/plugins/copy-code/copy-code.css';
import createEmojiPlugin from '@kangc/v-md-editor/lib/plugins/emoji/index';
import '@kangc/v-md-editor/lib/plugins/emoji/emoji.css';
// import VueVirtualScroller from 'vue-virtual-scroller';
// import 'vue-virtual-scroller/dist/vue-virtual-scroller.css';
import stickyHeader from 'el-table-sticky-header';
// Prism
import Prism from 'prismjs';
// highlight code
import 'prismjs/components/prism-json';

VMdPreview.use(vuepressTheme, {
  Prism,
});
// markdown支持流程图
VMdPreview.use(createMermaidPlugin());
// markdown支持显示代码行数
VMdPreview.use(createLineNumbertPlugin());
// markdown支持代码快速复制
VMdPreview.use(createCopyCodePlugin());
// markdown支持emoji
VMdPreview.use(createEmojiPlugin());

Vue.use(VMdPreview);
Vue.use(MITO.MitoVue);
Vue.use(VueCropper);
MITO.init({
  dsn: 'http://192.168.121.135:8887/test/webError',
  apikey: '123-2223-123-123',
});
import VueFullscreen from 'vue-fullscreen';
Vue.use(VueFullscreen);
import { registerMicroApps, start } from 'qiankun';
const mime = require('mime');

if (!window.localStorage.getItem('_accessTime_')) {
  window.localStorage.setItem('_accessTime_', new Date().getTime());
}

Vue.prototype.$mime = mime;

Vue.config.productionTip = false;
Object.keys(filters).forEach(key => Vue.filter(key, filters[key]));
Vue.use(autoFocus);
Vue.use(waterMaker);
Vue.directive('sticky-header', stickyHeader);
Vue.use(report);
// Vue.use(VueVirtualScroller);
Vue.use(ElementUI, {
  size: 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value),
});

// console.log('Registered Components:', Object.keys(ElementUI.components));

const getActiveRule = hash => location => location.hash.startsWith(hash);
const entry_map = process.env.NODE_ENV === 'production' ? '/map/' : '//localhost:8084';
const entry_log = process.env.NODE_ENV === 'production' ? '/log/' : '//localhost:8085';
registerMicroApps(
  [
    {
      name: 'refuel-map-station',
      entry: entry_map,
      container: '#container',
      //activeRule: '/map',    //vue-router为history模式
      activeRule: getActiveRule('#/child-map'), //vue-router为hash模式
      props: {
        store, // 主应用状态传给子应用
        router, // 主应用得路由信息给子应用，为了子应用触发主应用跳转
        appfunction: () => {
          // 自定义函数传递
          console.log('我是主');
        },
      },
      loader: boolean => {
        console.log(`loading状态${boolean}`);
      },
    },
    {
      name: 'refuel-log',
      entry: entry_log,
      container: '#container',
      //activeRule: '/map',    //vue-router为history模式
      activeRule: getActiveRule('#/child-log'), //vue-router为hash模式
      props: {
        store, // 主应用状态传给子应用
        router, // 主应用得路由信息给子应用，为了子应用触发主应用跳转
        appfunction: () => {
          // 自定义函数传递
          console.log('我是主');
        },
      },
      loader: boolean => {
        console.log(`loading状态${boolean}`);
      },
    },
  ],
  {
    beforeLoad: [
      app => {
        console.log(`${app.name}的beforeLoad阶段`);
      },
    ],
    beforeMount: [
      app => {
        console.log(`${app.name}的beforeMount阶段`);
      },
    ],
    afterMount: [
      app => {
        console.log(`${app.name}的afterMount阶段`);
      },
    ],
    beforeUnmount: [
      app => {
        console.log(`${app.name}的beforeUnmount阶段`);
      },
    ],
    afterUnmount: [
      app => {
        console.log(`${app.name}的afterUnmount阶段`);
      },
    ],
  }
);
// 启动 qiankun
start({
  prefetch: true,
});

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  components: {
    App,
  },
  template: '<App/>',
});
